package tlias.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tlias.pojo.*;
import tlias.pojo.StudentVO;
import tlias.service.StudentService;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    // 4.1 学员列表查询
    @GetMapping
    public Result list(StudentQueryParam param) {
        log.info("学员分页查询，参数：{}", param);
        PageResult<StudentVO> result = studentService.list(param);
        return Result.success(result);
    }

    // 4.2 删除学员
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable Integer[] ids) {
        log.info("删除学员：{}", ids);
        studentService.delete(ids);
        return Result.success();
    }

    // 4.3 添加学员
    @PostMapping
    public Result add(@RequestBody Student student) {
        log.info("添加学员：{}", student);
        studentService.add(student);
        return Result.success();
    }

    // 4.4 根据ID查询
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("根据ID查询学员：{}", id);
        StudentVO student = studentService.getById(id);
        return Result.success(student);
    }

    // 4.5 修改学员
    @PutMapping
    public Result update(@RequestBody Student student) {
        log.info("修改学员：{}", student);
        studentService.update(student);
        return Result.success();
    }

    // 4.6 违纪处理
    @PutMapping("/violation/{id}/{score}")
    public Result handleViolation(@PathVariable Integer id, @PathVariable Integer score) {
        log.info("学员违纪处理，ID：{}，扣分：{}", id, score);
        studentService.handleViolation(id, score);
        return Result.success();
    }
}